package com.stn.zjx.givingtreasure.net.impl;

import android.annotation.SuppressLint;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheEntity;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.callback.StringCallback;
import com.stn.zjx.givingtreasure.net.UserDynamicGuestApi;
import com.stn.zjx.givingtreasure.net.UserDynamicGuestGuestApi;
import com.stn.zjx.givingtreasure.utils.ToolsUtils;

import org.json.JSONObject;

public class UserDynamicGuestGuestNetImpl {


    /**
     * @apiNote 发表动态评论的回复
     * @param token token
     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void send_dynamic_guest_guest(String token,
                                              Integer toUserId,
                                              Integer userDynamicGuestId,
                                               String userDynamicGuestGuestContent,
                                              String tag, StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("toUserId",toUserId);
            jsonObject.put("userDynamicGuestId",userDynamicGuestId);
            jsonObject.put("userDynamicGuestGuestContent",userDynamicGuestGuestContent);
            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(UserDynamicGuestGuestApi.send_dynamic_guest_guest)
                .tag(tag)
                .isSpliceUrl(true)
                .upJson("")
                .params("token",token)
                .params("data",data)
                .execute(callback);

    }

    /**
     * @apiNote 动态评论回复分页

     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void query_dynamic_guest_guest(
            String token,
            Integer userDynamicGuestId,
            Integer pageNow,
            Integer pageSize,
            String tag, StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("userDynamicGuestId",userDynamicGuestId);
            jsonObject.put("pageNow",pageNow);
            jsonObject.put("pageSize",pageSize);
            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(UserDynamicGuestGuestApi.query_dynamic_guest_guest)
                .tag(tag)
                .cacheTime(CacheEntity.CACHE_NEVER_EXPIRE)
                .cacheKey(tag)
                .cacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)
                .isSpliceUrl(true)
                .upJson("")
                .params("token",token)
                .params("data",data)
                .execute(callback);

    }
}
